package com.zgroup.bean

public class DynamicGroovy {
  private GroovyObject groovyObject;

  public Object getProperty(String name) {
    return groovyObject.getProperty(name);
  }

  public Object invokeScriptMethod(String scriptName, String methodName, Object[] args) {
    ClassLoader parent = getClass().getClassLoader();
    GroovyClassLoader loader = new GroovyClassLoader(parent);
    try {
      Class groovyClass = loader.parseClass(new File(scriptName));
      groovyObject = (GroovyObject) groovyClass.newInstance();
      return groovyObject.invokeMethod(methodName, args);
    } catch (Exception e) {
      e.printStackTrace();
      return null;
    }
  }
}

